import com.haojin.mybatis.mapper.EmpMapper;
import com.haojin.mybatis.pojo.Emp;
import com.haojin.mybatis.pojo.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

/**
 * @author .29.
 * @create 2023-03-13 10:41
 */
public class testEmpMapper {
    //解决字段名跟属性名不一致导致查询不到值的问题：

    /**
     * 方案一：为字段设置别名，别名与属性名保持一致
     * 方案二：mybatis配置文件中，设置mapUnderscoreToCamelCase 为 true的全局配置
     * 方案三：mapper接口配置文件使用resultMap设置自定义映射
     */
    @Test
    public void testGetAllEmp(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
        System.out.println(mapper.getAllEmp());
    }

    @Test
    public void testGetEmpAndDept(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
        System.out.println(mapper.getEmpAndDept(1));
    }

    @Test
    public void testGetEmpAndDeptByStep(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
        Emp emp = mapper.getEmpAndDeptByStep1(2);
        System.out.println(emp.getEmpName());
        System.out.println("++++++++++++++++++++++");
        System.out.println(emp.getDept());
    }
}

